using System;
using System.Collections;
using System.Data;
using System.Windows.Forms;
using Syncfusion.Windows.Forms.Grid;
using ctsu.BaseForms;

namespace ctsu.Admin.BusLogic.CoreLab
{
	public class BLCoreLabFormGridTestLabels : BLCoreLabFormGridBaseImpl
	{


		public BLCoreLabFormGridTestLabels(FormGridMeta formGridMeta, GridControl grid, FormInfoBase formInfo, Form form)
			: base(formGridMeta, grid, formInfo, form)
		{

		}

		public override bool Initialize()
		{
			this.ExtendedProperties = new Hashtable();
			return base.Initialize();
		}

		protected override void DisplayRow(int row, DataRow dr)
		{
			for (int i = 1; i < this._grid.ColCount + 1; i++)
			{
				DataColumn dc = (DataColumn)this._grid[0, i].Tag;
				if (this._grid[row, i].CellType == "CheckBox")
				{
					if (dr[dc.ColumnName] != System.DBNull.Value)
					{
						if ((bool)dr[dc.ColumnName])
							this._grid[row, i].CellValue = "1";
						else
							this._grid[row, i].CellValue = "0";
					}
				}
				else
					this._grid[row, i].CellValue = dr[dc.ColumnName];

			}
		}

		public override void ReplaceRow(object obj, int row)
		{
			DataRow dr = (DataRow)this._grid[row, 0].Tag;
			Sample samp = (Sample)obj;

			if (samp.DrawID > 0)
			{
				this._grid[row, 2].CellValue = samp.DrawID;
				this._grid[row, 2].CellTipText = samp.GetDrawToolTip();
				this._grid[row, 2].Tag = samp;
				AssignChangeToDataRow(row, 2);
			}
			if (samp.TestType > -1)
			{
				this._grid[row, 3].CellValue = samp.TestType;
				AssignChangeToDataRow(row, 3);
			}
			if (samp.UnitOfMeasure > -1)
			{
				this._grid[row, 4].CellValue = samp.UnitOfMeasure;
				AssignChangeToDataRow(row, 4);
			}
			if (samp.Note.Length > 0)
			{
				this._grid[row, 5].Text = samp.Note;
				AssignChangeToDataRow(row, 5);
			}
			if (samp.SmallNote.Length > 0)
			{
				this._grid[row, 6].Text = samp.SmallNote;
				AssignChangeToDataRow(row, 6);
			}


			this._btnEditBatch.Enabled = true;
			this._btnRemoveBatch.Enabled = true;
			this._btnSave.Enabled = true;
		}

		public override void AddRow(object obj, int row)
		{
			Sample samp = (Sample)obj;
			DataRow dr = _data.NewRow();
			this._data.Rows.Add(dr);

			int rows = ++this._grid.RowCount;
			this._grid[rows, 0].Tag = dr;

			this._grid[rows, 2].CellValue = samp.DrawID;
			this._grid[rows, 2].CellTipText = samp.GetDrawToolTip();
			this._grid[rows, 2].Tag = samp;
			AssignChangeToDataRow(rows, 2);

			this._grid[rows, 3].CellValue = samp.TestType;
			AssignChangeToDataRow(rows, 3);
			this._grid[rows, 4].CellValue = samp.UnitOfMeasure;
			AssignChangeToDataRow(rows, 4);
			this._grid[rows, 5].Text = samp.Note;
			AssignChangeToDataRow(rows, 5);
			this._grid[rows, 6].Text = samp.SmallNote;
			AssignChangeToDataRow(rows, 6);

			this._btnEditBatch.Enabled = true;
			this._btnRemoveBatch.Enabled = true;
			this._btnSave.Enabled = true;
			this._grid.ScrollCellInView(this._grid.RowCount, 0);
		}

		protected override void Grid_CurrentCellChanged(object sender, EventArgs e)
		{
			base.Grid_CurrentCellChanged(sender, e);
			GridCurrentCell cc = this._grid.CurrentCell;
			if (cc.ColIndex == 2)
			{
				int draw = (int)cc.Renderer.ControlValue;
				BLFormTestLabels bl = (BLFormTestLabels)this.ExtendedProperties["BLForm"];
				Sample samp = (Sample)bl.htDrawSamples[draw];
				this._grid[cc.RowIndex, 2].CellTipText = samp.GetDrawToolTip();
				this._grid[cc.RowIndex, 2].Tag = samp;
			}
		}
	}
}

